<?php

namespace app\admin\model\choi;

use think\Model;
use traits\model\SoftDelete;

class Question extends Model
{

    use SoftDelete;

    

    // 表名
    protected $table = 'question';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [

    ];

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public static function getByName($name)
    {
        return self::where('name', $name)->find();
    }

    public function getInputList()
    {
        return ['radio' => __('Input radio'), 'checkbox' => __('Input checkbox'), 'text' => __('Input text')];
    }


    public static function getNotInId($languaegeId)
    {
        $id = LanguageQuestion::getQuestionId($languaegeId);
        return self::whereNotIn('question_id', $id)->order('weigh desc')->select();
    }




}
